﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Person.APi.Applation.CommandHandlers.EmployeeHandlers;

namespace T_Person.APi.Controllers
{
    /// <summary>
    /// 人事管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="mediator"></param>
        public EmployeeController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="employeerAddHandlers"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddEmployeeUser(EmployeerAddHandlers employeerAddHandlers)
        {
            return await mediator.Send(employeerAddHandlers);
        }
        /// <summary>
        /// 删除方法
        /// </summary>
        /// <param name="employeeDeleteHandler"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteEmployeeUserByid([FromQuery]EmployeeDeleteHandler employeeDeleteHandler)
        {
            return await mediator.Send(employeeDeleteHandler);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="employeeUpdateHandlers"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateEmployee(EmployeeUpdateHandlers employeeUpdateHandlers)
        {
            return await mediator.Send(employeeUpdateHandlers);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="employeeDeleteList"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DelteListEmployee([FromQuery]EmployeeDeleteList employeeDeleteList)
        {
            return await mediator.Send(employeeDeleteList);
        }
        /// <summary>
        /// 通过姓名更新状态
        /// </summary>
        /// <param name="employeeUpdateByNameHandlers"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int>UpdateEmployeeByname(EmployeeUpdateByNameHandlers employeeUpdateByNameHandlers)
        {
            return await mediator.Send(employeeUpdateByNameHandlers);
        }
        /// <summary>
        /// 通过主键更新状态
        /// </summary>
        /// <param name="employeeUpdateStateByidHandlers"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int>UpdateEmployeeByid(EmployeeUpdateStateByidHandlers employeeUpdateStateByidHandlers)
        {
            return await mediator.Send(employeeUpdateStateByidHandlers);
        }
    }
}
